package api

import (
	"docker_xzdream/service"

	"github.com/gin-gonic/gin"
)

func DownloadFile(c *gin.Context) {
	filePath := c.Query("path")
	fileName := c.Query("name")
	fileDir := "/home/nginx/data/files"

	c.Header("Content-Type", "application/octet-stream")
	c.Header("Content-Disposition", "attachment; filename="+fileName)
	c.Header("Content-Transfer-Encoding", "binary")
	c.File(fileDir + filePath + "/" + fileName)
	return
}

/**
文件列表
**/
func FileList(c *gin.Context) {
	dirPath := c.Query("dirPath")
	fileDir := "/home/nginx/data/files" + dirPath
	fileString, _ := (new(service.FileDir)).ReadFileList(fileDir)
	c.JSON(200, gin.H{"code": 0, "message": "成功", "data": fileString})
}
